<template>
  <div class="hljs">
    <el-form :model="dataFrom"
             size="small"
             ref="dataFrom"
             :rules="dataFormRules"
             style="text-align: left"
             label-width="140px">
      <div class="system">高审批异常次数配置</div>
      <el-form-item label="开始统计时间" prop="startTime">
        <el-date-picker
          v-model="dataFrom.startTime"
          type="date"
          style="width: 100%"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-for="(domain, index) in dataFrom.exceptionParamter"
                    :label="'审批异常次数' + (index + 1)"
                    :key="domain.key"
                    :prop="'exceptionParamter.'+ index +'.exceptionParamter'"
                   >
        <el-input-number v-model="domain.exceptionParamter" :min="1" :max="99999" style="width: 94%"/>
        <el-button @click.prevent="removeDomain(domain)" type="danger">删除</el-button>
      </el-form-item>
    </el-form>
    <div style="text-align: left">
      <el-button
        @click="submitForm"
        type="primary"
        size="small">
        保存
      </el-button>
      <el-button
        @click="addDomain"
        size="small">
        新增审批异常次数配置
      </el-button>
    </div>
  </div>
</template>

<script>
import {message} from "@/utils/message"
export default {
  props: {
    dataFrom: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data() {
    return {
      dataFormRules: {
        startTime: [{required: true, message: '请输入时间', trigger: ['blur', 'change'] }]
      }
    }
  },
  methods: {
    submitForm () {
      this.$refs['dataFrom'].validate(valid => {
        if (valid) {
          this.$emit('submitFormExamine', this.dataFrom)
        }
      })
    },
    addDomain () {
      this.dataFrom.exceptionParamter.push({
        exceptionParamter: '1',
        key: Date.now()
      })
    },
    removeDomain(item) {
      if (this.dataFrom.exceptionParamter.length === 1) {
        message({
          type: 'error',
          message: '至少配置一项审批异常次数配置'
        })
      } else {
        let index = this.dataFrom.exceptionParamter.indexOf(item)
        if (index !== -1) {
          this.dataFrom.exceptionParamter.splice(index, 1)
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
